package com.hfi.restful.web.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * @author ChangLiang
 * @date 2019/7/31
 */
@Component
@Aspect
public class TimeAspect {

    private Logger LOGGER = LoggerFactory.getLogger("timeFilterLogger");

    @Around("execution(* com.hfi.restful.web.controller.UserController.*(..))")
    public Object handleControllerMethod(ProceedingJoinPoint pjp) throws Throwable {
        LOGGER.info("time aspect start");

        Object[] args = pjp.getArgs();
        for (Object arg : args) {
            LOGGER.info(arg.toString());
        }

        long start = System.currentTimeMillis();
        // 放行
        Object proceed = pjp.proceed();
        LOGGER.info("time aspect耗时 " + (System.currentTimeMillis() - start) + "ms");
        LOGGER.info("time aspect end");

        return proceed;
    }
}
